package com.jia.videos.controller;


import com.jia.videos.common.lang.R;
import com.jia.videos.entity.Category;
import com.jia.videos.service.CategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dujiajia
 * @since 2020-12-20
 */
@RestController
@RequestMapping("/videos/category")
@CrossOrigin
@Api(tags = "分类管理")
public class CategoryController {

    @Autowired
    CategoryService categoryService;


    @GetMapping("info/{id}")
    public R info(@PathVariable Long id){
        Category category = categoryService.getById(id);
        return R.ok().data("data",category);
    }

    @GetMapping("tree")
    public R tree() {
        List<Category> list = categoryService.selectTree();
        return R.ok().data("data",list);
    }

    @GetMapping("list")
    public R list() {
        List<Category> list = categoryService.getAll();
        return R.ok().data("data",list);
    }

    @PostMapping("save")
    public R save(@RequestBody Category category) {
        categoryService.save(category);
        return R.ok();
    }

    @PutMapping("update")
    public R update(@RequestBody Category category){
        categoryService.updateById(category);
        return R.ok();
    }
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id) {
        categoryService.removeById(id);
        return R.ok();
    }
    @DeleteMapping("deleteBatch")
    public R deleteBatch(@RequestBody List<Long> list){
        categoryService.removeByIds(list);
        return R.ok();
    }
}

